/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbean.CI.Profile;

import entity.AES;
import entity.Employee;
import java.awt.event.ActionEvent;
import javax.ejb.EJB;
import javax.el.ELContext;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import managedbean.Controller;
import session.stateless.EmployeeBeanLocal;

/**
 *
 * @author Vincent
 */
@ManagedBean
@ViewScoped
public class EditProfileManagerBean {
    @EJB
    private EmployeeBeanLocal employeeBeanLocal;
    
    private Employee employeeToEdit;
    private String statusMessage;
    
    /** Creates a new instance of EditProfileManagerBean */
    public EditProfileManagerBean() {
    }

    public Employee getEmployeeToEdit() {
        return employeeToEdit;
    }

    public void setEmployeeToEdit(Employee employeeToEdit) {
        this.employeeToEdit = employeeToEdit;
    }
    
    public void initView(PhaseEvent event){
        ELContext elContext = FacesContext.getCurrentInstance().getELContext();
        Controller controller = (Controller) FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elContext, null, "controller");
        this.employeeToEdit = controller.getEmployee();
    }
    
    public void updateExistingEmployee(ActionEvent event)
    {
        statusMessage = "Successful!";
        employeeBeanLocal.updateEmployee(employeeToEdit.getEmployeeId(), employeeToEdit.getEmployeeEmail(), employeeToEdit.getEmployeeContactNumber(), employeeToEdit.getEmployeeAddress());

        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,  "Update Profile Result: " +statusMessage , "")); 
    }   
}
